package Q288

import java.util.ArrayList


class Main {

}

/**
 * 汇总区间
 * @author 23737
 * @date 2022.5.6
 */
fun main() {

}

class Solution {
    fun summaryRanges(nums: IntArray): List<String> {
        val ans: MutableList<String> = ArrayList()
        var sb = StringBuilder()
        for (i in nums.indices) {
            if (!(i + 1 < nums.size && nums[i] == nums[i + 1] - 1)) {
                if (sb.length > 0) sb.append("->")
                sb.append(nums[i])
                ans.add(sb.toString())
                sb = StringBuilder()
            } else {
                if (sb.length == 0) sb.append(nums[i])
            }
        }
        return ans
    }
}